<?php


namespace app\common\model;


use think\Db;
use think\Model;

class UserIncomeLog  extends Model
{
    // 表名
    protected $name = 'user_income_log';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 追加属性
    protected $append = [
    ];

    static public function setLog($income_id,$user_id,$money, $msg = '')
    {
        Db::startTrans();
        try {
            self::create([
                'income_id' => $income_id,
                'user_id' => $user_id,
                'money' => $money,
                'msg' => $msg,
            ]);

            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
        }
    }

    public function user()
    {
        return $this->belongsTo("User", 'user_id', 'id')->setEagerlyType(0);
    }
}